<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户列表</title>
    <jsp:include page="../part/css/user_list.jsp" flush="true"/>
    <jsp:include page="../part/js/user_list.jsp" flush="true"/>

    <style>
        #user-list-container {
            position: relative;
            text-align: center;
            min-width: 400px;
            width: 30%;
            margin: 0 auto;
            display: grid;
            grid-template-columns: 1fr;
            justify-content: center;
            align-items: center;
            background: transparent;
            backdrop-filter: blur(10px);
            grid-gap: 10px;
            padding: 30px;
            top: 50%;
            transform: translateY(-50%);
            border-radius: 30px;
        }

        #user-list-container h2.title {
            grid-column: 1 / span 1;
            font-size: 30px;
            font-weight: bold;
            color: #0089ff;
            margin-bottom: 20px;
        }

        #user-list-table table {
            table-layout: fixed;
        }

        #user-list-table table thead tr th {
            text-align: center;
            padding: 10px;
            font-size: 16px;
            font-weight: bold;
            color: white;
            min-width: 100px;
            border-bottom: 1px solid #0089ff;
            border-top: 1px solid #0089ff;
            border-left: 1px solid #0089ff;
            border-right: 1px solid #0089ff;
            background: #0089ff;
            position: sticky;
            top: 0;
        }

        #user-list-table table tbody tr td {
            min-width: 200px;
            text-align: center;
            padding: 10px;
            font-size: 16px;
            font-weight: bold;
            color: white;
            border-bottom: 1px solid #0089ff;
            border-top: 1px solid #0089ff;
            border-left: 1px solid #0089ff;
            border-right: 1px solid #0089ff;

            /**
            换个适配的背景
             */
            background: #0089ff;
            backdrop-filter: blur(10px);
        }

        #user-list-table table tbody tr td:last-child, #user-list-table table thead tr th:last-child {
            position: sticky;
            right: 0;
        }


    </style>
</head>
<body>

<div id="user-list-container">
    <h2 class="title">欢迎来到用户管理页面</h2>
    <div class="btn-group">
        <c:if test="${token_info.user.type==2}">
            <button primary="" onclick="window.location.href='${pageContext.request.contextPath}/register.html'">添加用户
            </button>
            <button warning="">删除用户</button>
            <button warning="" onclick="toedit(${token_info.user.id})">修改个人信息</button>
        </c:if>

        <c:if test="${token_info.user.type==1}">
            <button warning="">修改个人信息</button>
        </c:if>
        <button primary="" onclick="logout()">退出登录</button>
    </div>
    <div id="user-list-table" style="width: 100%;height: 50vh;overflow: auto">
        <table>
            <thead>
            <tr>
                <th>id</th>
                <th>用户名</th>
                <th>邮箱</th>
                <th>手机号</th>
                <th>用户类型</th>
                <th>操作</th>
            </tr>
            </thead>

            <tbody>
            <c:forEach items="${list}" var="item">
            <tr>
                <td title="${item.id}">${item.id}</td>
                <td title="${item.username}">${item.username}</td>
                <td title="${item.email}">${item.email}</td>
                <td title="${item.mobile}">${item.mobile}</td>
                <td>${item.type==1?'管理员':'普通用户'}</td>
                <td>
                    <button primary onclick="toedit(${item.id})">修改</button>
                    <button warning onclick="deleteUser(${item.id})">删除</button>
                </td>
            </tr>
            </c:forEach>
        </table>
    </div>
</div>
<script>
    function toedit(id) {
        window.location.href = '${pageContext.request.contextPath}/user/edit.html?id=' + id;
    }

    function deleteUser(id) {
        if (confirm('确定要删除吗？')) {
            window.location.href = '${pageContext.request.contextPath}/user/delete?id=' + id;
        }
    }

    function logout() {
        if (confirm('确定要退出登录吗？')) {
            window.location.href = '${pageContext.request.contextPath}/logout';
        }
    }
</script>
</body>
</html>
